package com.tudouji.project.pay.domain;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.flow.service.pojo.BasePojo;
import com.flow.service.pojo.flow.FlowTempNode;
import com.flow.service.pojo.result.FlowResult;
import com.tudouji.project.flow.domain.Flowtempnode;
import com.tudouji.project.harvest.domain.Freightorder;
import com.tudouji.project.purchasebill.domain.Purchasebill;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 支付对象 payinfo
 *
 * @author tudouji
 * @date 2021-04-06
 */
@Data
public class Payinfo extends BasePojo
{
    /** 主键 */
    private String guid;

    /** 支付申请编号 */
    @Excel(name = "支付申请编号",width = 30,mergeRely = {0},mergeVertical = true)
    private String code;
    /** 采收主体NAME */
    @Excel(name = "采收/购主体",width = 30,mergeRely = {0},mergeVertical = true)
    private String orgname;
    @Excel(name = "供应商",width = 30,mergeRely = {0},mergeVertical = true)
    private String supplierName;
    @Excel(name = "车数",width = 30,mergeRely = {0},mergeVertical = true, type = 10, isStatistics = true)
    private Integer carnum;
    @Excel(name = "结算金额",width = 30,mergeRely = {0},mergeVertical = true, isStatistics = true)
    private BigDecimal amount;
    private BigDecimal applyAmount;
    private BigDecimal settlement;
    @Excel(name = "已付",width = 30,mergeRely = {0},mergeVertical = true, isStatistics = true)
    private BigDecimal preamount;
    /** 未支付金额 */
    @Excel(name = "未付",width = 30,mergeRely = {0},mergeVertical = true, isStatistics = true)
    private BigDecimal recamount;
    @Excel(name = "订单编号",width = 30)
    private String bsCode;
    @Excel(name = "产品",width = 30)
    private String productname;
    @Excel(name = "规格",width = 30)
    private String spname;
    @Excel(name = "库房",width = 30)
    private String storeroom;


    /** 已支付金额 */

    /** 支付金额 */
//    @Excel(name = "申请金额")

    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "创建时间", width = 30, format = "yyyy-MM-dd HH:mm:ss",mergeRely = {0},mergeVertical = true)
    private Date createdate;
    @Excel(name = "操作人",width = 30,mergeRely = {0},mergeVertical = true)
    private String operatorrealname;
    /** 状态(0-删除 1-正常 2-已支付) */
    @Excel(name = "状态",width = 30,mergeRely = {0},mergeVertical = true)
    private String statusname;


    private BigDecimal endAmount;//尾款

    private Integer status;


    /** 操作人 */
    private String operatorid;

    /** 最后更新时间 */
    private Date lastupdate;

    /** 总重量（吨） */
    private BigDecimal weight;

    /** 部门id */
    private String departid;

    /** 部门 */
    private String departname;

    /** 流程id */
    private String flowid;


    /** 库房id */
    private String srguid;

    /** 开户行 */
    private String bank;

    /** 银行账号 */
    private String bankcode;

    /** 采收主体id */
    private String orgid;

    /** 是否收到发票:1 收到 或 2 未收到 */
    private Integer invoiceon;

    private String plantorguid;
    private String plantorname;
    private String company;
    private String typename;
    private String invoiceonname;

    private Integer applyType;
    private String parentPayinfoGuid;

    //申请类型	1-采收付款 2-采购付款
    private Integer businessType;
    private Long supplierId;
    private Long storermId;
    private Long orgId;
    private Long deptId;
    //1-继续支付，默认1，否则不继续支付
    private Integer continuepayFlag;

    private String[] departids;
    private String[] strguids;
    private Integer[] stats;
    private List<FlowTempNode> nodes;

    private String percent;
    private String applyPercent;
    private String operatorloginname;
    private String search;


    private BigDecimal price;
    private String endTime;
    private String beginTime;

    private List<Payorderlist> items;

    private List<Freightorder> itemsFo;
    private List<Purchasebill> itemsFl;

    //货运单ids
    private String freightorderIds;
    @Override
    public void prepareForProcess(){
        setBusTable("payinfo");
        setPlatformId(storermId);
    }

    @Override
    public boolean backToStartNode(FlowResult result){

        if (getPreamount()!=null
            && getPreamount().compareTo(BigDecimal.ZERO) > 0){
            result.setMsg("已发起付款申请，不能退回到发起");
            return false;
        }
        return  true;
    }
}
